package com.hehua.Adapter;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.util.Objects;

public class XmlUtil {
    public static Object getBean(){
        try{
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document document;
            document = builder.parse("src//com//hehua//Adapter//config.xml");
            NodeList className = document.getElementsByTagName("className");
            Node child = className.item(0).getFirstChild();
            String nodeValue = child.getNodeValue();
            Class<?> forName = Class.forName(nodeValue);
            Object instance = forName.newInstance();
            return instance;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
